﻿namespace PerpetuumSoft.InstrumentationPDA
{
    using PerpetuumSoft.InstrumentationPDA.Mathematics;
    using System;
    using System.Drawing;

    public class Switch : SwitchBase
    {
        private Color activeLedColor = Color.LightGreen;
        private Color darkColor = Color.Gray;
        private int depth = 4;
        private PerpetuumSoft.InstrumentationPDA.FaceStyle faceStyle = PerpetuumSoft.InstrumentationPDA.FaceStyle.RaisedNotch;
        private Color inactiveLedColor = Color.Green;
        private Size ledSize = new Size(20, 10);
        private Color lightColor = Color.Silver;
        private Color lightLightColor = Color.Gainsboro;
        private Color middleColor = Color.DarkGray;
        private Color notchDarkColor = SystemColors.ControlDark;
        private Color notchLightColor = SystemColors.ControlLightLight;

        protected override void DrawDynamic(Graphics g)
        {
            Vector vector6;
            Vector vector7;
            Brush brush;
            base.DrawDynamic(g);
            bool flag = (base.Checked && !base.Reverse) || (!base.Checked && base.Reverse);
            VectorRectangle workRectangle = this.WorkRectangle;
            Vector location = new Vector(base.Direction, workRectangle.X, workRectangle.Y);
            Vector vector2 = new Vector(base.Direction, workRectangle.Width, workRectangle.Height);
            Vector size = new Vector(base.Direction, vector2.X, vector2.Y / 2M);
            Vector vector4 = new Vector(base.Direction, vector2.X, (vector2.Y / 2M) - this.depth);
            Vector vector5 = new Vector(base.Direction, vector2.X, this.depth);
            if (flag)
            {
                vector6 = new Vector(base.Direction, location.X, location.Y + (vector2.Y / 2M));
                vector7 = new Vector(base.Direction, location.X, (location.Y + vector2.Y) - this.depth);
                VectorRectangle rectangle2 = new VectorRectangle(location, size).PositiveRectangle();
                VectorRectangle rectangle3 = new VectorRectangle(vector6, vector4).PositiveRectangle();
                VectorRectangle rectangle4 = new VectorRectangle(vector7, vector5).PositiveRectangle();
                g.FillRectangle(new SolidBrush(this.LightColor), rectangle2.Round());
                g.FillRectangle(new SolidBrush(this.LightLightColor), rectangle3.Round());
                g.FillRectangle(new SolidBrush(this.DarkColor), rectangle4.Round());
            }
            else
            {
                vector6 = new Vector(base.Direction, location.X, location.Y + this.depth);
                vector7 = new Vector(base.Direction, location.X, location.Y + (vector2.Y / 2M));
                VectorRectangle rectangle5 = new VectorRectangle(location, vector5).PositiveRectangle();
                VectorRectangle rectangle6 = new VectorRectangle(vector6, vector4).PositiveRectangle();
                VectorRectangle rectangle7 = new VectorRectangle(vector7, size).PositiveRectangle();
                g.FillRectangle(new SolidBrush(this.LightLightColor), rectangle5.Round());
                g.FillRectangle(new SolidBrush(this.MiddleColor), rectangle6.Round());
                g.FillRectangle(new SolidBrush(this.LightColor), rectangle7.Round());
            }
            if (base.Checked)
            {
                brush = new SolidBrush(this.activeLedColor);
            }
            else
            {
                brush = new SolidBrush(this.inactiveLedColor);
            }
            if (!base.Reverse)
            {
                if (!base.Checked)
                {
                    size = new Vector(base.Direction, location.X + ((vector2.X / 2M) - (this.ledSize.Width / 2)), (location.Y + 3M) + this.depth);
                }
                else
                {
                    size = new Vector(base.Direction, location.X + ((vector2.X / 2M) - (this.ledSize.Width / 2)), location.Y + 3M);
                }
                vector4 = new Vector(base.Direction, this.ledSize.Width, this.ledSize.Height);
            }
            else
            {
                if (!base.Checked)
                {
                    size = new Vector(base.Direction, (location.X + vector2.X) - ((vector2.X / 2M) - (this.ledSize.Width / 2)), ((location.Y + vector2.Y) - 3M) - this.depth);
                }
                else
                {
                    size = new Vector(base.Direction, (location.X + vector2.X) - ((vector2.X / 2M) - (this.ledSize.Width / 2)), (location.Y + vector2.Y) - 3M);
                }
                vector4 = new Vector(base.Direction, -this.ledSize.Width, -this.ledSize.Height);
            }
            VectorRectangle rectangle8 = new VectorRectangle(size, vector4).PositiveRectangle();
            g.FillRectangle(brush, rectangle8.Round());
            if (this.faceStyle != PerpetuumSoft.InstrumentationPDA.FaceStyle.Smooth)
            {
                decimal height = vector2.Height;
                decimal secodary = (location.Y + (vector2.Height / 2M)) + 4M;
                if (base.Checked)
                {
                    height -= this.depth;
                }
                if (base.Reverse)
                {
                    height -= vector2.Height / 2M;
                    secodary -= vector2.Height / 2M;
                    if (base.Checked)
                    {
                        height += this.depth;
                        secodary += this.depth;
                    }
                }
                Pen pen = new Pen(this.NotchLightColor);
                Pen pen2 = new Pen(this.NotchDarkColor);
                if (this.faceStyle == PerpetuumSoft.InstrumentationPDA.FaceStyle.RaisedNotch)
                {
                    pen2 = new Pen(this.NotchLightColor);
                    pen = new Pen(this.NotchDarkColor);
                }
                while (secodary <= height)
                {
                    vector7 = new Vector(base.Direction, location.X + 2M, secodary);
                    vector6 = new Vector(base.Direction, (location.X + vector2.Width) - 4M, secodary);
                    g.DrawLine(pen2, (int) vector7.X, (int) vector7.Y, (int) vector6.X, (int) vector6.Y);
                    //vector7 = new Vector(base.Direction, location.X + 2M, decimal.op_Increment(secodary));
                    vector7 = new Vector(base.Direction, location.X + 2M, (secodary++));
                    //vector6 = new Vector(base.Direction, (location.X + vector2.Width) - 4M, decimal.op_Increment(secodary));
                    vector6 = new Vector(base.Direction, (location.X + vector2.Width) - 4M, (secodary++));
                    g.DrawLine(pen, (int) vector7.X, (int) vector7.Y, (int) vector6.X, (int) vector6.Y);
                    secodary += 3M;
                }
            }
        }

        public Color ActiveLedColor
        {
            get
            {
                return this.activeLedColor;
            }
            set
            {
                if (this.activeLedColor != value)
                {
                    this.activeLedColor = value;
                    base.Invalidate();
                }
            }
        }

        public Color DarkColor
        {
            get
            {
                return this.darkColor;
            }
            set
            {
                if (this.darkColor != value)
                {
                    this.darkColor = value;
                    base.Invalidate();
                }
            }
        }

        protected override Size DefaultControlSize
        {
            get
            {
                return new Size(40, 100);
            }
        }

        public int Depth
        {
            get
            {
                return this.depth;
            }
            set
            {
                if (this.depth != value)
                {
                    this.depth = value;
                    base.Invalidate();
                }
            }
        }

        public PerpetuumSoft.InstrumentationPDA.FaceStyle FaceStyle
        {
            get
            {
                return this.faceStyle;
            }
            set
            {
                if (this.faceStyle != value)
                {
                    this.faceStyle = value;
                    base.Invalidate();
                }
            }
        }

        public Color InactiveLedColor
        {
            get
            {
                return this.inactiveLedColor;
            }
            set
            {
                if (this.inactiveLedColor != value)
                {
                    this.inactiveLedColor = value;
                    base.Invalidate();
                }
            }
        }

        public Size LedSize
        {
            get
            {
                return this.ledSize;
            }
            set
            {
                if (this.ledSize != value)
                {
                    this.ledSize = value;
                    base.Invalidate();
                }
            }
        }

        public Color LightColor
        {
            get
            {
                return this.lightColor;
            }
            set
            {
                if (this.lightColor != value)
                {
                    this.lightColor = value;
                    base.Invalidate();
                }
            }
        }

        public Color LightLightColor
        {
            get
            {
                return this.lightLightColor;
            }
            set
            {
                if (this.lightLightColor != value)
                {
                    this.lightLightColor = value;
                    base.Invalidate();
                }
            }
        }

        public Color MiddleColor
        {
            get
            {
                return this.middleColor;
            }
            set
            {
                if (this.middleColor != value)
                {
                    this.middleColor = value;
                    base.Invalidate();
                }
            }
        }

        public Color NotchDarkColor
        {
            get
            {
                return this.notchDarkColor;
            }
            set
            {
                if (this.notchDarkColor != value)
                {
                    this.notchDarkColor = value;
                    base.Invalidate();
                }
            }
        }

        public Color NotchLightColor
        {
            get
            {
                return this.notchLightColor;
            }
            set
            {
                if (this.notchLightColor != value)
                {
                    this.notchLightColor = value;
                    base.Invalidate();
                }
            }
        }
    }
}

